/*
 * Copyright 2008, 2009 Kobi Krasnoff
 * 
 * This file is part of "Catch Falling Coins".
 *
 * "Catch Falling Coins" is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * "Catch Falling Coins" is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with "Catch Falling Coins".  If not, see <http://www.gnu.org/licenses/>.
 *
 */

import java.io.IOException;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;

/**
 * This is a sprite which declares the Gripe!
 * @author kobi
 *
 */
public class GripeSprite extends Sprite {
	private int ScreenWidth = 0; 
	private Image mainImage;
	private static final int MOVE_RIGHT_TOP = 19, MOVE_RIGHT_BOTTOM = 12;
	private static final int MOVE_LEFT_TOP = 7, MOVE_LEFT_BOTTOM = 0;
	private static final int TURN_MIDDLE = 10;
		
	public GripeSprite(Image img)
	{
		super(img);
		try
		{
			mainImage = Image.createImage("/images/GripeTotalSprite.png");
		}
		catch (IOException ioe) {}
		this.setImage(mainImage, 32, 32);
		this.setFrame(TURN_MIDDLE);
	}
	
	public void setScreenWidth(int ScreenWidth)
	{
		this.ScreenWidth = ScreenWidth;
	}
	
	public void moveStand()
	{
		this.setFrame(TURN_MIDDLE);
	}
	
	public void moveRight()
	{
		if (this.getX() + 32 < ScreenWidth)
		{
			this.nextFrame();
			if (this.getFrame() >= MOVE_RIGHT_TOP)
				this.setFrame(MOVE_RIGHT_BOTTOM);
			this.move(2, 0);
		}
	}
	
	public void moveLeft()
	{
		if (this.getX() > 0)
		{
			this.move(-2, 0);
			this.prevFrame();
			if (this.getFrame() <= MOVE_LEFT_BOTTOM)
				this.setFrame(MOVE_LEFT_TOP);
		}
	}
}
